asList

infix fun <E> Expect<Array<E>>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<Array<E>>(source)(source)

Expects that the subject of this expectation holds all assertions the given assertionCreator creates for the subject as List.

The transformation as such is not reflected in reporting. Use feature of({ f(it::asList) }, assertionCreator) if you want to show the transformation in reporting.

Return

The newly created Expect for the transformed subject.

Since

0.12.0

Samples

expect(arrayOf("A", "B"))
    .asList { // subject within this expectation-group is of type List<String>
        it toEqual listOf("A", "B")
    } // subject here is back to type Array<String>

fails {
    // all expectations inside an expectation-group are evaluated together; for more details see:
    // https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group
    expect(arrayOf("A", "B"))
        .asList {
            it toContain "C"  // fails
            it toContain "D"  // still evaluated even though above `toContain` already fails
            //                   use `asList o` if you want a fail fast behaviour
        }
}

@JvmName(name = "asListEOut")
infix fun <E> Expect<Array<out E>>.asList(assertionCreator: Expect<List<E>>.() -> Unit): Expect<Array<out E>>(source)(source)

Expects that the subject of this expectation holds all assertions the given assertionCreator creates for the subject as List.

The transformation as such is not reflected in reporting. Use feature of({ f(it::asList) }, assertionCreator) if you want to show the transformation in reporting.

Return

The newly created Expect for the transformed subject.

Since

0.12.0

Samples

expect<Array<out String>>(arrayOf("A", "B"))
    .asList { // subject within this expectation-group is of type List<String>
        it toEqual listOf("A", "B")
    } // subject here is back to type Array<out String>

fails {
    // all expectations inside an expectation-group are evaluated together; for more details see:
    // https://github.com/robstoll/atrium#define-single-expectations-or-an-expectation-group
    expect<Array<out String>>(arrayOf("A", "B"))
        .asList {
            it toContain "C" // fails
            it toContain "D" // still evaluated even though above `toContain` already fails
            //                  use `asList o` if you want a fail fast behaviour
        }
}